let CACHE_VERSION = 1;
let CACHE_NAME = 'cache_v' + CACHE_VERSION;
let CACHE_URLS = [
  '/home'
  /* '/index.js',
  '/js/app.js',
  '/js/chunk-vendors.js', */
];

self.addEventListener('install',event => {
  event.waitUntil(
    caches.open(CACHE_NAME).then(cache => {
      return cache.addAll(CACHE_URLS)
    })
  )
})

self.addEventListener('activate', event => {
	event.waitUntil(
	  Promise.all([
	  	self.clients.claim(),
	  	caches.keys().then(cacheList => {
	  		return Promise.all(
	  			cacheList.map(cacheName => {
	  				if(cacheName !== CACHE_NAME){
	  					return cache.delete(cacheName)
	  				}
	  			})
	  		)
	  	})
	  ])
	)
});

self.addEventListener('fetch', event => {
  
  event.respondWith(
    caches.match(event.request)
      .then(response => {
        if (response) {
          return response;
        }
        return fetch(event.request);
      }
    )
  );
});